{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "view-in-github"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/mk7exe/millerite/blob/master/Phase3/Millerite_NN_Predict.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "aZ8NPdz13ggU"
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import h5py\n",
    "%tensorflow_version 2.x\n",
    "import tensorflow as tf\n",
    "from tensorflow import keras\n",
    "from tensorboard.plugins.hparams import api as hp\n",
    "import datetime\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "zEcU9PxN3wpU"
   },
   "source": [
    "Loading the dataset to evaluate from Github."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 33
    },
    "colab_type": "code",
    "id": "5AZW1b0-3r6S",
    "outputId": "9673b265-d999-4a59-fe1c-81a6f8f282d1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-04-28 01:16:42 URL:https://raw.githubusercontent.com/mk7exe/millerite/master/Phase2/datasets/slab.h5 [688888/688888] -> \"slab.h5.2\" [1]\n"
     ]
    }
   ],
   "source": [
    "! wget -nv https://github.com/mk7exe/millerite/raw/master/Phase2/datasets/slab.h5\n",
    "root_path = '.'\n",
    "dataset = h5py.File(root_path + '/slab.h5', \"r\")\n",
    "# x_orig = np.array(dataset[\"test_set_x\"][:]) \n",
    "# y_orig = np.array(dataset[\"test_set_y\"][:]) \n",
    "x_orig = np.array(dataset[\"slab_x\"][:]) \n",
    "y_orig = np.array(dataset[\"slab_y\"][:]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 296
    },
    "colab_type": "code",
    "id": "VcHXBLpJRitF",
    "outputId": "e72f1272-0e79-4703-c31d-dcbf20b63e94"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2453, 68) (2453, 1) (2453, 1) (2453, 1)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3de5RU5Znv8e8vSLwiGmQSFEwzihiNVzqox+ggEzwYjejEjMSYgAcXk0xMNJrl4FmJUcyZo8maGI2oh4NGjERwvCStYpQJGKMnIhdFBFHxEsWQiIioiaDAc/7Yu7EsdnVVd9euqu7+fdaq5b68u/pp+y2e2u/e+3kVEZiZmRX7SL0DMDOzxuQEYWZmmZwgzMwskxOEmZllcoIwM7NM29U7gGrZY489oqmpqd5hWDe2aNGi1yOif61/rvu25amtft1tEkRTUxMLFy6sdxjWjUn6Yz1+rvu25amtfu0hJrMqk9RL0uOS7snYt72kWZJWSpovqan2EZpVxgnCrPrOBZ4usW8CsC4i9gWuBK6oWVRm7eQEYVZFkgYCJwLTSjQZA0xPl28H/lGSahGbWXs5QZhV10+BC4EtJfbvBbwCEBGbgPVAv+JGkiZKWihp4Zo1a/KK1axNThBmVSLpJOC1iFjU2feKiKkR0RwRzf371/zGKTPACcKsmo4GTpb0EjATGCnplqI2rwKDACRtB/QF1tYySLNKOUGYVUlEXBQRAyOiCRgLzI2IM4uatQDj0uXT0jYuqWwNqds8B2HWqCRNBhZGRAtwA/ALSSuBN0gSiVlDcoIwy0FEPAg8mC5fXLB9A/Cl+k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ZI3oWl/gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light",
      "tags": []
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "xsum = np.sum(x_orig, axis=1, keepdims=True)\n",
    "\n",
    "y_orig = y_orig.reshape((x_orig.shape[0], 1))\n",
    "y_temp = np.divide(y_orig, xsum)\n",
    "\n",
    "print(x_orig.shape, y_orig.shape, xsum.shape, y_temp.shape)\n",
    "\n",
    "plt.figure()\n",
    "plt.subplot(1,2,1)\n",
    "# the histogram of the data\n",
    "n, bins, patches = plt.hist(y_orig, 50, density=True)\n",
    "plt.xlabel('original y')\n",
    "plt.ylabel('Probability')\n",
    "plt.subplot(1,2,2)\n",
    "# the histogram of the data\n",
    "n, bins, patches = plt.hist(y_temp, 50, density=True)\n",
    "plt.xlabel('scaled y')\n",
    "plt.ylabel('Probability')\n",
    "plt.show()\n",
    "\n",
    "y_orig = y_temp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "HkEvbRaE4I4c"
   },
   "source": [
    "Mounting google drive to load trained model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 33
    },
    "colab_type": "code",
    "id": "fEgT6dNH4A4t",
    "outputId": "1b54ebe3-2980-4fe6-a2db-78422988cd53"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount(\"/content/gdrive\", force_remount=True).\n"
     ]
    }
   ],
   "source": [
    "from google.colab import drive\n",
    "drive.mount('/content/gdrive')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "KH5CFpvl7Zjy"
   },
   "source": [
    "Defining the model to load (in case there are multiple models saved in Google Drive)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "O4mdXmkG7eXG"
   },
   "outputs": [],
   "source": [
    "drive_path = 'gdrive/My Drive/Colab Notebooks/models'\n",
    "model_date = '20200428-011840'\n",
    "model_path = drive_path + '/' + model_date"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "t7SkpD5X7tKc"
   },
   "source": [
    "Getting feature scalling parameters from Google Drive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "B65IYvto8Bvj"
   },
   "outputs": [],
   "source": [
    "xmean_path = model_path + '/xmean.txt'\n",
    "xmean = np.genfromtxt(xmean_path, delimiter=',')\n",
    "\n",
    "xrange_path = model_path + '/xrange.txt'\n",
    "xrange = np.genfromtxt(xrange_path, delimiter=',')\n",
    "\n",
    "y_path = model_path + '/ymean_yrange.txt'\n",
    "with open(y_path) as f:\n",
    "  lines=f.readlines()\n",
    "  temp = lines[1].split()\n",
    "  ymean = temp[0]\n",
    "  yrange = temp[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "OztMi75NGDsO"
   },
   "source": [
    "Applying the feature scaling to x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "SYv2kZDYGb13"
   },
   "outputs": [],
   "source": [
    "x = np.divide(np.subtract(x_orig, xmean), xrange)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "z9yqZWUR6kiC"
   },
   "source": [
    "Defining the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "urm2M7g86aQp"
   },
   "outputs": [],
   "source": [
    "hparams = {\n",
    "    'num_layers': 3,\n",
    "    'num_units': 30,\n",
    "    'dropout': 0.1,\n",
    "    'alpha': 0.001,\n",
    "    'lambdaL2': 0.01,\n",
    "    'last_activation': 'linear',\n",
    "    'activation': 'relu'\n",
    "    }\n",
    "\n",
    "def train_model(hparams):\n",
    "  num_layers = hparams['num_layers']\n",
    "  num_units = hparams['num_units']\n",
    "  activation = hparams['activation']\n",
    "  lambdaL2 = hparams['lambdaL2']\n",
    "  dropout = hparams['dropout']\n",
    "  learning_rate = hparams['alpha']  \n",
    "  out_activation = hparams['last_activation']\n",
    "\n",
    "  model = keras.Sequential()\n",
    "  model.add(keras.layers.Flatten(input_shape=x.shape[1:]))\n",
    "\n",
    "  for i in range(num_layers):\n",
    "    model.add(keras.layers.Dense(num_units, kernel_regularizer=\n",
    "                               keras.regularizers.l2(lambdaL2), use_bias=False))\n",
    "    model.add(keras.layers.BatchNormalization())\n",
    "    model.add(keras.layers.Activation(activation))\n",
    "    model.add(keras.layers.Dropout(dropout))\n",
    "\n",
    "  model.add(keras.layers.Dense(1, activation=out_activation))\n",
    "\n",
    "  adam = keras.optimizers.Adam(learning_rate=learning_rate,\n",
    "                               beta_1=0.9, beta_2=0.999) \n",
    "  model.compile(optimizer=adam, \n",
    "                loss=keras.losses.mean_squared_error, \n",
    "                metrics=[tf.keras.metrics.RootMeanSquaredError()])\n",
    "  return model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "S72yUKe1HeXS"
   },
   "source": [
    "Loading the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 33
    },
    "colab_type": "code",
    "id": "DJgcgesx6F9h",
    "outputId": "08f29afe-6095-4dc7-c875-2bc6456ae569"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.training.tracking.util.CheckpointLoadStatus at 0x7fd5cf615d68>"
      ]
     },
     "execution_count": 41,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = train_model(hparams)\n",
    "model_name = model_path + '/model'\n",
    "model.load_weights(model_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 33
    },
    "colab_type": "code",
    "id": "uIf2uMzd5_mw",
    "outputId": "f5930195-e6ca-4d18-cd58-68bf8a7a3ef4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RMSE=  0.14596917562793119\n"
     ]
    }
   ],
   "source": [
    "y_pred = model.predict(x)\n",
    "yrange = float(yrange)\n",
    "ymean = float(ymean)\n",
    "\n",
    "y_bar = np.multiply(y_pred, yrange) + ymean \n",
    "#y_bar = np.multiply(y_bar, xsum)\n",
    "\n",
    "RMSE = np.sqrt(np.mean(np.square(np.subtract(y_bar, y_orig))))\n",
    "\n",
    "# for i in range(len(y_pred)):\n",
    "#   print(y_bar[i], y_orig[i], np.divide(np.abs(y_orig[i]) - np.abs(y_bar[i]), \n",
    "#         y_orig[i]))\n",
    "\n",
    "print(\"RMSE= \", RMSE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "gXVH_l61KSQX"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "authorship_tag": "ABX9TyMggiCYXcE+fGAH7vWm4cYm",
   "include_colab_link": true,
   "name": "Millerite_NN_Predict.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
